package mydessertstore.persistence.impl;

import mydessertstore.persistence.DBUtil;
import mydessertstore.persistence.LogDao;

import java.sql.Connection;
import java.sql.PreparedStatement;

public class LogDAOImpl implements LogDao {
    private static final String insertLogString = "insert into userlog (username, log) VALUES (?, ?)";

    @Override
    public void insertLog(String username, String logInfo) {
        try {
            Connection connection = DBUtil.getConnection();
            PreparedStatement preparedStatement = connection.prepareStatement(insertLogString);
            preparedStatement.setString(1, username);
            preparedStatement.setString(2, logInfo);

            preparedStatement.executeUpdate();
            DBUtil.closeStatement(preparedStatement);
            DBUtil.closeConnection(connection);
            //测试用 System.out.println("执行了inserlog操作");
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
